package com.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.mapper.StuMapper;
import com.shop.pojo.Stu;
import com.shop.service.StuService;
import com.shop.vo.StuQueryRequest;
import com.shop.vo.StuSaveRequest;
import com.shop.vo.StuUpdateRequest;
import org.springframework.beans.BeanUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.metadata.IPage;


@Service("stuService")
public class StuServiceImpl extends ServiceImpl<StuMapper, Stu> implements StuService {

    @Override
    public IPage<Stu> page(Page page, StuQueryRequest request){
        QueryWrapper<Stu> wrapper = Stu.queryWrapper(request);
        return this.page(page,wrapper);
    }

    @Transactional
    @Override
    public void save(StuSaveRequest request){
        Stu stu = new Stu();
        BeanUtils.copyProperties(request,stu);
        this.save(stu);
    }

    @Transactional
    @Override
    public void update(StuUpdateRequest request){
        Stu stu = new Stu();
        BeanUtils.copyProperties(request,stu);
        this.updateById(stu);
    }

    @Transactional
    @Override
    public void delete(Integer id){
        UpdateWrapper<Stu> updateWrapper = new UpdateWrapper();
        this.update(updateWrapper);
    }

}